<?php
if (!defined('IN_XLP')) {
    exit('Access Denied');
}
$Document = array(
    'pageid' => 'news-cate', //页面标示
    'pagename' => '知学分类', //当前页面名称
    'mycss' => array(), //加载的css样式表
    'myjs' => array(), //加载的js脚本
	//'footerjs'=>array('content/highcharts', 'content/exporting',),
    'footerjs'=>array('content/fuelux/fuelux','content/combodate/moment.min'),
    'head' => true, //加载头部文件
);

include getTpl('header', 'public');
?>
<!--顶部导航 开始-->
<?php include getTpl('top', 'public');?>
<!--顶部导航 结束-->
<!--左侧菜单 开始-->
<?php include getTpl('nav', 'public');?>
<!--左侧菜单 结束-->
<!--主体 开始-->
<!-- content -->
    <section id="content">
     <section class="main padder">
        <div class="clearfix"> 
          <h4><i class="fa fa-table"></i>分类管理</h4> 
        </div>
        <div class="row">
      
      <!-- table 11 -->
      <div class="col-lg-12"> 
        <section class="panel"> 
          <header class="panel-heading">
          知学分类
          </header> 
          <div class="panel-body"> 
            <div class="row text-small"> 
              <div class="col-sm-8 m-b-mini">
                <a href="<?php echo U('news/cateAdd'); ?>" class="btn btn-sm btn-white">添加</a>
              </div>

              <!--  -->
               <div class="panel-body"> 
                <div class="row text-small"> 
                <form action="<?php echo U('news/cate'); ?>" method="get">
                
                 <div class="col-sm-4">
                  <div class="input-group"> 
                   <input type="text" class="input-sm form-control" placeholder="Search" name="keyword" id="keyword" value="<?php echo $keyword; ?>"> 
                   <span class="input-group-btn"> <button class="btn btn-sm btn-white" type="submit">搜索</button> </span> 
                  </div> 
                 </div> 
                 </form>
                </div> 
               </div> 
              <!--  -->
            </div> 
          </div>
          <style>.table th,.table td,.table input{text-align:center;}</style>
          <div class="table-responsive"> 
            <table class="table table-striped b-t text-small"> 
              <thead> 
                <tr>
                  <th width="100">ID</th> 
                  <th width="200">分类名称</th> 
                  <th>父分类</th> 
                  <th width="250">是否显示</th> 
                  <th width="150">排序</th>
                  <th width="50">操作</th> 
                </tr> 
              </thead> 
              <tbody>
              <?php foreach ($list as $key => $value) { ?>
                <tr> 
                  <td><?php echo $value['id']; ?></td> 
                  <td><div><input id="cate_name_<?php echo $value['id']; ?>" type="text" value="<?php echo $value['name']; ?>" class="form-control"></div></td> 
                  <td>
                    <select name="" id="" class="form-control" disabled>
                      <?php foreach ($list as $keyy => $valuee): ?>
                        <?php if ($value['id'] != $valuee['id']): ?>
                          <option value="<?php echo $valuee['id'] ?>" <?php if($valuee['id'] == $value['pid']) echo 'selected' ?>><?php echo $valuee['name'] ?></option>
                        <?php endif ?>
                      <?php endforeach ?>
                      <option value="0"  <?php if(0 == $value['pid']) echo 'selected' ?> >顶级分类</option>
                    </select>
                  </td> 
                  <td>
                    <div class="row">
                      <div class="col-xs-4 radio m-l-large"><label class="radio-custom"> <input type="radio" name="is_show_<?php echo $value['id']; ?>" value="1" <?php if($value['is_show'] == 1) echo 'checked="checked"' ?> /> <i class="fa fa-circle-o"></i>显示</label></div>
                      <div class="col-xs-4 radio m-l-large" style="margin-top: 9px;"><label class="radio-custom"> <input type="radio" name="is_show_<?php echo $value['id']; ?>" value="0" <?php if($value['is_show'] == 0) echo 'checked="checked"' ?> /> <i class="fa fa-circle-o"></i>隐藏</label></div>
                    </div>
                  </td> 
                  <td>
                    <div>
                      <input type="number" value="<?php echo $value['sort']; ?>" class="form-control">
                    </div>
                  </td> 
                  <td>
                    <div class="btn-group"> 
                      <button class="btn btn-white btn-xs dropdown-toggle" data-toggle="dropdown">操作<span class="caret"></span></button> 
                      <ul class="dropdown-menu"> 
                          <li><a href="javascript:;" onclick="save(<?php echo $value['id']; ?>, this)">保存</a></li>
                          <li><a href="javascript:;" onclick="del('<?php echo $value['id']; ?>', this)">删除</a></li>
                      </ul>  
                    </div>
                  </td> 
                </tr>
              <?php } ?>
              </tbody> 
            </table> 
          </div> 
          <footer class="panel-footer"> 
            <div class="row"> 
              <div class="col-sm-12 text-right text-center-sm"> 
                <?php echo page($total,$page,'',20,'page');?>  
              </div> 
            </div> 
          </footer> 
        </section> 
      </div>
        </div> 
    </section>
  </section> 
  <!--/ content --> 
<!--主体 结束-->
<script>
$(function(){

})
/**
 * 保存分类修改
 */
function save(id, obj){
  $.get('<?php echo U('news/ajax');?>',
    {type:'cateSave', id:id, name:$('#cate_name_'+id).val()},
    function(result){
      Msg.hide();
      if (result.status==1){
      Msg.ok(result.info);
      self.location.reload();
    }else{
      Msg.error(result.info);
    }
    },'json');
}

/**
 * 删除分类
 */
 function del (id, obj) {
   $.get('<?php echo U('news/ajax');?>',{type:'cateDel', id:id},function(result){
    Msg.hide();
    if (result.status==1){
      Msg.ok(result.info);
      var s = $(obj).parent().parent().parent().parent().parent().hide();
    }else{
      Msg.error(result.info);
    }
    },'json');
 }
</script>
<?php
include getTpl('footer', 'public');
?>